<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        let login = function(v) {
            return new Promise((resolve) => {
                setTimeout(() => {
                    resolve('login')
                }, 200)
            })
        }

        let getVipInfo = function(v) {
            return new Promise((resolve, reject) => {
                console.log(v)
                setTimeout(() => {
                    resolve('getVipInfo')
                }, 2000)
            })
        }

        let isRemind = function(v) {
            return new Promise((resolve) => {
                console.log(v)
                setTimeout(() => {
                    resolve('isRemind')
                }, 200)
            })
        }

        let show = function* (v) {
            let res = yield login(v)
            res = yield getVipInfo(res)
            res = yield isRemind(res)
        }

        let show_2 = async () => {
            let res = await login()
            res = await getVipInfo(res)
            res = await isRemind(res)
        }
        show_2();

        // 循环/递归

        let res
        while((res = fn.next()).done === false) {
            res = fn.next()
        }
        
        // 递归
        let run = (generator) => {
            let fn = show();
            const next = (data) => {
                let res = fn.next(data)
                if (res.done) {
                    console.log('done');
                    return res.value
                }
                res.value.then((data) => {
                    next(data);
                })
            }
            next()
        }

        run(show)


    </script>
</body>
</html>